using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CutRope : MonoBehaviour
{
    public List<Transform> tsList = new List<Transform>();
    private LineRenderer line;

    private void Start()
    {
        line = gameObject.AddComponent<LineRenderer>();
        line.material = RopeManager.instance.lineMaterial;
        line.startWidth = 0.25f;
        line.endWidth = 0.25f;
        line.textureMode = LineTextureMode.Tile;
        // Invoke("Disappear", 0.2f);
    }

    private void Update()
    {
        if (GameManager.instance.win)
        {
            Invoke("destroyLine", 1.5f);
            return;
        }
        line.positionCount = tsList.Count;
        for (int i = 0; i < tsList.Count; i++)
        {
            line.SetPosition(i, tsList[i].position);
        }
    }

    private void Disappear()
    {
        Destroy(gameObject);
    }

    public void destroyLine()
    {
        LineRenderer line = gameObject.GetComponent<LineRenderer>();
        if (line != null)
        {
            Destroy(line);
        }
    }
}
